package oop.controller.action.section;

import oop.controller.action.DefaultAction;
import oop.data.Question;
import oop.data.Section;
import oop.db.dao.SectionDAO;

public class DeleteQuestionAction extends DefaultAction {

	@Override
	public void perform() throws Exception {
		try {
			Section section = SectionDAO.fetchById(
					Long.parseLong(request.getParameter("id"))).get(0);
			Question question = section.getQuestionById().get(
					Long.parseLong(request.getParameter("questionId")));
			section.removeQuestion(question);
		} catch (NumberFormatException ex) {
			request.setAttribute("message", "ID không hợp lệ");
			setNextAction("error");
		}
	}

}
